﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace App.lib.controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:CurrentUserStore runat=server></{0}:CurrentUserStore>")]
    public class CurrentUserStore : HiddenField
    {
        [Bindable(true)]
        public Guid UserID
        {
            get
            {
                MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                if (user != null) return (Guid)user.ProviderUserKey;
                return Guid.Empty;
            }
        }
        [Bindable(true)]
        public string UserName
        {
            get
            {
                MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                if (user != null) return user.UserName;
                else return null;
            }
        }
        public override string Value
        {
            get
            {
                MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                if (user != null) return user.ProviderUserKey.ToString();
                return Guid.Empty.ToString();
            }
            set
            {
                //SvOtchet.DataModel.sp.GetPeriodListTableAdapters.QueriesTableAdapter qta = new SvOtchet.DataModel.sp.GetPeriodListTableAdapters.QueriesTableAdapter();
                //qta.GetAllowPeriods(
                base.Value = value;
            }
        }


    }
}
